<template>
    <div class="Livebroadcastcardpurchases">
        <div class="Livebroadcastcardpurchase">
            <div class="Livebroadcastcardpurchase-head">
                <h1>  助学师学习卡  </h1>
            </div>
            <div class="Livebroadcastcardpurchase-select">
                <ul>
                    <li v-for="(item,index) in learnCardInfo" :key="index" @click="goselect(index)" >
                        <label :class="priceListIndex ==index?'navelecet':''">
                            <h3>{{item.title}}学习卡</h3>
                            <span class="equity">权益说明</span>
                            <span>可预约{{item.title}}<span v-if="item.title !== '私教'">助学师</span>,语言不限</span>
                            <span>一节课25~30分钟</span>
                            <span>不得转让，一经购买不得退回</span>
                            <span>有效期一个月，过期退回</span>
                        </label>
                    </li>
                </ul>
            </div>  
            <div class="Theprice">
                    <ul>
                        <li v-for="(item,index) in priceList" :key="index" @click="chooseMemeber(index)">
                            <label class="Theprice-img">
                                <img src="/images/major.png" alt="" v-if="item.type == 'major'">
                                <img src="/images/crossborder.png" alt="" v-if="item.type == 'cross_border'">
                                <img src="/images/moteher.png" alt="" v-if="item.type == 'mother_tongue'">
                            </label>
                            <label>
                                <span>{{item.time_type}}</span>
                            </label>
                            <label class="Theprice-price">
                                <span>¥{{item.discount_amout}}</span>
                                <span>¥{{item.amout}}</span>
                            </label>
                            <label class="Confirm" >
                                <div class="Theprice-coursenum" style="position:absolute;left:100px" v-if="index == 0">({{item.course_num}}节)</div>
                                <div class="Theprice-coursenum" style="position:absolute;left:376px" v-if="index == 1">({{item.course_num}}节)</div>
                                <div class="Theprice-coursenum" style="position:absolute;left:660px" v-if="index == 2">({{item.course_num}}节)</div>
                                <img src="/images/确认.png" alt="" v-if="chooseMemeberIndex == index">
                            </label>
                        </li>
                    </ul>
                    <label>
                        <span @click="confirmBuy()">立即购买</span>
                    </label>
                </div>
        </div>
    </div>
</template>
<script>
import $ from 'jquery';
export default {
    name:'buyHelpLearnCard',
    data(){
        return{
            userinfo:JSON.parse(localStorage.getItem('userinfo')),
            priceListIndex:'',
            Purchasequantity:'',
            chooseMemeberIndex:0,
            learnCardInfo:[
                // {
                //     title:'私教',
                // },
                {
                    title:'母语',
                },
                {
                    title:'跨境',
                },
                {
                    title:'专业',
                }
            ],
            priceInfo:[],
            priceList:[],
        }
    },
    mounted(){
        this.getPriceList()
        this.toTop()
        console.log(this.$route.query)
    },
    methods: {
        toTop() {
            let top = document.documentElement.scrollTop || document.body.scrollTop;// 实现滚动效果 
            const timeTop = setInterval(() => {
                document.body.scrollTop = document.documentElement.scrollTop = top -= 50;
                if (top <= 0) {
                    clearInterval(timeTop);
                }
            }, 10);
        },
        aliPay(e){
            let data = {
                app_id:'2019071565816606',
                method:'alipay.trade.page.pay',
                charset	:'utf-8',
                sign_type:'RSA2',
            }
            this.$axios({
                    method:'POST',
                    url:'',
                    data:data,
                }).then((res) =>{
                    console.log(res.data.data)
                }).catch((error) =>{
                    console.log(error)
                })
        },
        confirmBuy(){
            let info = this.priceList[this.chooseMemeberIndex]
    
            let data = {
                rcharge_abstract:'助学师学习卡',
                rcharge_type:'study_card',
                user_id:this.userinfo.user_id,
                amount:info.discount_amout,//充值金额
                source:'pc',
                study_type:info.type,//学习课类型
                studycard_id:info.id,//学习卡Id
                course_num:info.course_num,//课数
                member_duration : "3",
                member_level : "3",
            }
            console.log('购买信息',data)
            this.$axios({
                    method:'POST',
                    url:'http://101.37.66.151:8768/eg-api/user/pay/aliPay',
                    data:data,
                }).then((res) =>{
                    var data = res.data.data
                    document.querySelector('body').innerHTML = res.data.data;
                    const div = document.createElement('div') // 创建div
                    div.innerHTML = res.data.data // 将返回的form 放入div
                    document.body.appendChild(div)
                    document.forms[0].submit()
                    // this.aliPay(res.data.data)
                }).catch((error) =>{
                    console.log(error)
                })
        },
        chooseMemeber(e){
            this.chooseMemeberIndex = e
        },
        getPriceList(){
            console.log('获取列表')
            let data = {
                user_id : this.userinfo.user_id,
            };
            this.$axios({
                    method:'get',
                    url:'http://101.37.66.151:8768/eg-api/user/studyCard/query',
                    params:data,
                }).then((res) =>{
                    console.log(res.data.data,'价格列表')
                    this.priceInfo = res.data.data
                    let title = this.$route.query.title
                    if(/跨境/.test(title)){
                        this.goselect(1)
                    }
                    // else if(/私教/.test(title)){
                    //     this.goselect(0)
                    // }
                    else if(/专业/.test(title)){
                        this.goselect(2)
                    }else if(/母语/.test(title)){
                        this.goselect(0)
                    }

                }).catch((error) =>{
                    console.log(error)
                })
        },
        goselect(e){//选项卡切换
            this.priceListIndex = e
            this.priceInfo.map(item=>{
                if(item.type == 'mother_tongue' && e == 0){
                    this.priceList = item.studyPriceEntities
                }else if(item.type == "cross_border" && e ==1){
                    this.priceList = item.studyPriceEntities
                }else if (item.type == "major" && e ==2){
                    this.priceList = item.studyPriceEntities
                }
            })
            console.log(this.priceList)
        }
    }
}
</script>
<style lang="less" scoped>
.Theprice{
        position: relative;
        width: 80%;
        margin: 0 auto;
        margin-top: 80px;
        padding-bottom: 100px;
    }
    .Theprice>ul{
        width: 100%;
        display: flex;
        list-style: none;
        justify-content: space-between;
        padding: 0;
        li{
            width: 30%;
            height: 180px;
            border: 1px solid #ccc;
            display: flex;
            flex-wrap: wrap;
            cursor: pointer;
        }
    }
    .Theprice>ul>li>label{
        width: 100%;
        height: 30px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        span{
            font-size: 24px;
            color: #303030;
            font-family: FZCQJW--GB1-0;
            font-weight: bold;
        }
        
    }
    .Theprice-price{
        span{
            width: 41%;
            text-align: center;
            margin-top: 10px;
            &:first-child{
                color: #F74444;
                font-size: 29px;
                font-weight: bold;
                font-family: MicrosoftYaHeiLight;
            }
            &:last-child{
                width: 10%;
                color: #D7D7D7;
                font-size: 20px;
                text-decoration:line-through;
                font-weight: normal;
            }
        }
    }
    .Theprice-coursenum{
        font-size: 17px;
        width: 52px;
        margin-right: 59px;
        position: relative;
        left: 30px;
    }
    .Theprice>label{
        display: flex;
        width: 100%;
        height: 40px;
        align-items: center;
        justify-content: center;
        margin-top: 130px;
        span{
            width: 30%;
            height: 40px;
            background:linear-gradient(0deg,rgba(255,77,77,1),rgba(222,39,39,1));
            border-radius:21px;
            line-height: 40px;
            color: #FFFFFF;
            font-size: 16px;
            cursor: pointer;
            text-align: center;
        }
    }
    .Theprice-img{
        width: 50%;
        display: flex;
        align-items: flex-start!important;
        justify-content: flex-start!important;
        height: auto!important;
        img{
            width: 40%;
            text-align: left;
            float: left;
        }
    }
    .Confirm{
        width: 50%;
        display: flex;
        align-items: flex-end!important;
        justify-content: flex-end!important;
        height: 40px!important;
        margin-top: -18px;
        img{
            width: 10%;
            text-align: left;
            float: left;
        }
    }
    .Livebroadcastcardpurchases{
        position: relative;
        width: 100%;
        background: #ffffff;
        height: 1037px;
        margin-top: -22px;
        border-radius: 15px;
    }
    .Livebroadcastcardpurchase{
        position: relative;
        width: 90%;
        margin: 0 auto;
    }
    .Livebroadcastcardpurchase-head{
        position: relative;
        width: 100%;
        height: 160px;
        line-height: 160px;
        text-align: center;
        color: #2DC7C8;
        font-size: 18px;
        ::before{
            top: -6px;
            color: #47cecf;
            font-size: 13px;
            content: '————————';
            position: relative;
            left: -11px;
        }
        ::after{
            top: -6px;
            color: #47cecf;
            font-size: 13px;
            content: '————————';
            position: relative;
            left: 11px;
        }
    }
    .Livebroadcastcardpurchase-select{
        position: relative;
        width: 100%;    
    }
    .Livebroadcastcardpurchase-select>label{
        display: flex;
        ul{
            display: flex;
            width: 100%;
            list-style: none;
            padding: 0;
            justify-content: space-between;
            li{
                width: 33%;
                text-align: center;
                color: #2DC7C8;
            }
        }
    }
    .Livebroadcastcardpurchase-select>ul{
        display: flex;
        width: 100%;
        height: 230px;
        list-style: none;
        padding: 0;
        justify-content: space-between;
        li{
            width: 33%;
            text-align: center;
            color: #2DC7C8;
            label{
                position: relative;
                width: 90%;
                height: 230px;
                margin: 0 auto;
                cursor: pointer;
                display: flex;
                justify-content: center;
                flex-wrap: wrap;
                border:1px solid rgba(51,197,198,1);
                border-radius:10px;
                span{
                    width: 100%;
                    height: 20px;
                    margin-top: -10px;
                    font-size: 12px;
                }
                .equity{
                    // ::before{
                    //     content: '——';
                    //     background: linear-gradient(to right, red, blue);
                    // }
                }
            }
        }
    }
    .navelecet{
        background: #33C5C6;
        color: #ffffff;
    }
    .Livebroadcastcardpurchase-input{
        display: flex;
        width: 100%;
        height: 200px;
        justify-content: space-between;
        margin-top: 60px;
    }
    .Livebroadcastcardpurchase-input>label:first-child{
        width: 50%;
        height: 100%;
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        align-items: center;
        background: #2DC7C8;
        color: #FFFFFF;
        input{
            width: 60%;
            height:40px;
            border:1px solid rgba(255,255,255,1);
            border-radius:10px;
            outline: none;
            padding-left: 4%;
        }
        p{
            display: block;
            width: 100%;
            text-align: center;
            font-size: 16px;
        }
    }
    .Livebroadcastcardpurchase-input>label:last-child{
        width: 40%;
        height: 100%;
        border:1px dashed rgba(78,207,207,1);
        span{
            display: inline-block;
            width: 100%;
            height: 40px;
            align-items: center;
            color: #FF7336;
            padding-left: 4%;
            margin-top: 10%;
        }
        ul{
            display: flex;
            padding-left: 4%;
            flex-wrap: wrap;
            list-style-position: inside;
            font-size: 14px;
            text-align: center;
        }
    }
    .Theamountof{
        position: relative;
        width: 30%;
        height: 60px;
        text-align: center  ;
        margin: 0 auto;
        margin-top: 80px;
        label{
            display: flex;
            width: 100%;
            height:100%;
            border:1px solid rgba(45,199,200,1);
            border-radius:20px;
            justify-content: center;
            align-items: center;
            span{
                &:last-child{
                    font-size: 26px;
                    color: #FF4E4E;
                    font-weight: bold;
                }
            }
        }
    }
    .shopqrcode{
        position: relative;
        width:12%;
        height: 73px;
        text-align: center  ;
        margin: 0 auto;
        margin-top: 20px;
        label{
            display: flex;
            width: 100%;
            height:83px;
            justify-content: center;
            align-items: center;
            border:1px solid rgba(78,207,207,1);
            border-radius:5px;
            img{
                width:auto;
                height:auto;
                max-width:90%;
                max-height:90%;
            }
        }
    }
    .Theamountof-way,.Theamountof-agreement,.Theamountof-payment{
        position: relative;
        width:20%;
        height: auto    ;
        text-align: center  ;
        margin: 0 auto;
        margin-top: 20px;
    }
    .Theamountof-agreement{
        width: 40%;
        color: #3ACBCC;
        font-size: 14px;
    }
    .Theamountof-payment{
        padding-bottom: 60px;
        span{
            display: inline-block;
            width: 100%;
            height: 40px;
            line-height: 40px;
            background:rgba(58,203,204,1);
            border-radius:20px;
            color: #ffffff;
            cursor: pointer;
        }
    }
</style>